package com.pocketmenu.temp;


import com.pocketmenu.ui.R;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

	public final static String EXTRA_MESSAGE = "com.pocketmenu.app.MESSAGE";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    /** Called when the user clicks the Send button */
    public void sendMessage(View view) {
    	
    	String phoneNumber = ((EditText) findViewById(R.id.phone_number)).getText().toString();
    	String message = ((EditText) findViewById(R.id.edit_message)).getText().toString();
    	
    	if(phoneNumber.length() > 0 && message.length() > 0)
    		sendSMS(phoneNumber, message);
    	   	
    	/*
    	Intent intent = new Intent(this, DisplayMessageActivity.class);
    	
    	String message = editText.getText().toString();
    	intent.putExtra(EXTRA_MESSAGE, message);
    	
    	startActivity(intent);
    	*/
    }
    
    /** Called when the user clicks the Send button */
    public void testDatabase(View view) {    	    	
    	Intent intent = new Intent(this, TestDatabaseActivity.class);        	
    	startActivity(intent);    	
    }    
    
    //---sends an SMS message to another device---
    private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    }    
}
